public class LeetCode235 {
    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        TreeNode ans = root;
        while (p.val < ans.val && q.val < ans.val || ans.val < p.val && ans.val < q.val) {//在同一侧
            //小于当前节点 像左找
            if (p.val < ans.val) {
                ans = ans.left;
            } else {
                //否则向右找
                ans = ans.right;
            }
        }
        return ans;
    }
}
